package com.resjz.milddog.config;

/*import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.security.crypto.codec.Base64;
import org.springframework.security.jwt.crypto.sign.RsaVerifier;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
import org.springframework.security.oauth2.provider.token.store.KeyStoreKeyFactory;
import org.springframework.util.FileCopyUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.KeyPair;
import java.util.stream.Collectors;

/**
 * @author Administrator
 * @version 1.0
 **/
/*@Configuration
public class TokenConfig {

    private String PubliceKey = "publice.key";

    @Bean
    public TokenStore tokenStore() {
        //JWT令牌存储方案
        return new JwtTokenStore(accessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter accessTokenConverter() {
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
       // converter.setVerifierKey(getPublicKey());
        String publicKey = getPublicKey();
        converter.setVerifier(new RsaVerifier(publicKey));
        converter.setVerifierKey(publicKey);
        		//不设置这个会出现 Cannot convert access token to JSON

        return converter;
    }
    private String getPublicKey(){
        Resource resource = new ClassPathResource(PubliceKey);
        String publicKey;
        try {
            publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
            return publicKey;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /*@Bean
    public TokenStore tokenStore() {
        //使用内存存储令牌（普通令牌）
        return new InMemoryTokenStore();
    }
}*/
